<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box1 {
            background-color: aqua;
            width: 300px;
            height: 300px;
        }

        #box2 {
            width: 150px;
            height: 150px;
            background-color: aquamarine;
        }
    </style>
</head>

<body>
    <script src="https://cdn.staticfile.org/vue/2.7.0/vue.min.js"></script>
    <div id="box">
        <button @click="fn1()">选项1</button>
        <button @click="fn2()">选项2</button>
        <ul>
            <li v-if="num==1">
                <a href="https://www.yjwujian.cn/" @click.prevent="">点击不跳转阻止默认事件</a>
            </li>
            <li v-if="num==2">
                <div id="box1" @click="a()">
                    父盒子
                    <div id="box2" @click.stop="b()">子盒子</div>
                </div>
            </li>
        </ul>
    </div>
    <script>
        new Vue({
            el: "#box",
            data: {
                num: 1,
            },
            methods: {
                fn1() {
                    return this.num = 1
                },
                fn2() {
                    return this.num = 2
                },
                a() {
                    var a = document.getElementById("box1")
                    a.style.backgroundColor = "red"
                },
                b() {
                    var a = document.getElementById("box2")
                    a.style.backgroundColor = "blue"
                }
            },
            computed: {},
            filters: {}
        })
    </script>
</body>

</html>